package com.dalin.platform.etl.model;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.dalin.common.base.BaseObject;
import com.dalin.platform.etl.condition.EtlTableInfoCondition;
import com.dalin.platform.pub.PlatContext;
/*****************************************************************************
 * @content: 类信息                                                   *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-05-11                                                     *
 * @modDate: 2010-05-11                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
@Entity
@Table(name="ETL_DATABASE_INFO")
public class EtlDatabaseInfoEntity extends BaseObject {
    private Long databaseId; // DATABASE_ID,16,0
    private String hostIp; // HOST_IP,32,0
    private Integer port; // PORT,8,0
    private String databaseName; // DATABASE_ENGLISH_NAME,64,0
    private String databaseComment; // DATABASE_CHINESE_NAME,128,0
    private String userName; // USER_NAME,64,0
    private String userPswd; // USER_PSWD,64,0
    private Integer databaseType; // DATABASE_TYPE,8,0
    private Integer databaseDriver; // DATABASE_DRIVER,8,0
    private String remark; // REMARK,256,0
    private Date createDate; // CREATE_DATE,7,0
    private Date modifyDate; // MODIFY_DATE,7,0


    @Id
    @Column(name="DATABASE_ID")
    @GeneratedValue(strategy = GenerationType.TABLE,generator="generator_normal")
    @TableGenerator(
        name = "generator_normal",
        table = "GLB_GENERATOR_KEY",
        pkColumnName = "GEN_KEY",
        valueColumnName = "GEN_VALUE",
        pkColumnValue = "ETL_DATABASE_INFO",
        allocationSize=1
    )
    public Long getDatabaseId() {
        return databaseId;
    }

    public void setDatabaseId(Long databaseId) {
        this.databaseId = databaseId;
    }

    @Column(name="HOST_IP")
    public String getHostIp() {
        return hostIp;
    }

    public void setHostIp(String hostIp) {
        this.hostIp = hostIp;
    }

    @Column(name="PORT")
    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    @Column(name="DATABASE_NAME")
    public String getDatabaseName() {
		return databaseName;
	}

	public void setDatabaseName(String databaseName) {
		this.databaseName = databaseName;
	}
	
    @Column(name="DATABASE_COMMENT")
    public String getDatabaseComment() {
		return databaseComment;
	}

	public void setDatabaseComment(String databaseComment) {
		this.databaseComment = databaseComment;
	}
	
	
    @Column(name="USER_NAME")
    public String getUserName() {
        return userName;
    }

	public void setUserName(String userName) {
        this.userName = userName;
    }

    @Column(name="USER_PSWD")
    public String getUserPswd() {
        return userPswd;
    }

    public void setUserPswd(String userPswd) {
        this.userPswd = userPswd;
    }

    @Column(name="DATABASE_TYPE")
    public Integer getDatabaseType() {
        return databaseType;
    }

    public void setDatabaseType(Integer databaseType) {
        this.databaseType = databaseType;
    }

    @Column(name="DATABASE_DRIVER")
    public Integer getDatabaseDriver() {
        return databaseDriver;
    }

    public void setDatabaseDriver(Integer databaseDriver) {
        this.databaseDriver = databaseDriver;
    }

    @Column(name="REMARK")
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="CREATE_DATE")
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="MODIFY_DATE")
    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    
    
    @Transient
	public List<EtlTableInfoEntity> getTableInfoEntitys() {
    	EtlTableInfoCondition cond = new EtlTableInfoCondition();
    	cond.setDatabaseId(this.getDatabaseId());
		return PlatContext.getDao().queryObjsToPages(cond.prepareParams()
				.getPreparedPageQuery());
	}

	
	
    @Override
    public int hashCode() {
        int njlrst = 17;
        njlrst = 31 * njlrst + (databaseId == null ? 0 : databaseId.hashCode());
        njlrst = 31 * njlrst + (hostIp == null ? 0 : hostIp.hashCode());
        njlrst = 31 * njlrst + (port == null ? 0 : port.hashCode());
        njlrst = 31 * njlrst + (databaseName == null ? 0 : databaseName.hashCode());
        njlrst = 31 * njlrst + (databaseComment == null ? 0 : databaseComment.hashCode());
        njlrst = 31 * njlrst + (userName == null ? 0 : userName.hashCode());
        njlrst = 31 * njlrst + (userPswd == null ? 0 : userPswd.hashCode());
        njlrst = 31 * njlrst + (databaseType == null ? 0 : databaseType.hashCode());
        njlrst = 31 * njlrst + (databaseDriver == null ? 0 : databaseDriver.hashCode());
        njlrst = 31 * njlrst + (remark == null ? 0 : remark.hashCode());
        njlrst = 31 * njlrst + (createDate == null ? 0 : createDate.hashCode());
        njlrst = 31 * njlrst + (modifyDate == null ? 0 : modifyDate.hashCode());
        return njlrst;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof EtlDatabaseInfoEntity)) return false;
        final EtlDatabaseInfoEntity other = (EtlDatabaseInfoEntity) o;
        if (databaseId == null) {
            if (other.databaseId != null) return false;
        } else if (!databaseId.equals(other.databaseId)) {
            return false;
        }
        if (hostIp == null) {
            if (other.hostIp != null) return false;
        } else if (!hostIp.equals(other.hostIp)) {
            return false;
        }
        if (port == null) {
            if (other.port != null) return false;
        } else if (!port.equals(other.port)) {
            return false;
        }
        if (databaseName == null) {
            if (other.databaseName != null) return false;
        } else if (!databaseName.equals(other.databaseName)) {
            return false;
        }
        if (databaseComment == null) {
            if (other.databaseComment != null) return false;
        } else if (!databaseComment.equals(other.databaseComment)) {
            return false;
        }
        if (userName == null) {
            if (other.userName != null) return false;
        } else if (!userName.equals(other.userName)) {
            return false;
        }
        if (userPswd == null) {
            if (other.userPswd != null) return false;
        } else if (!userPswd.equals(other.userPswd)) {
            return false;
        }
        if (databaseType == null) {
            if (other.databaseType != null) return false;
        } else if (!databaseType.equals(other.databaseType)) {
            return false;
        }
        if (databaseDriver == null) {
            if (other.databaseDriver != null) return false;
        } else if (!databaseDriver.equals(other.databaseDriver)) {
            return false;
        }
        if (remark == null) {
            if (other.remark != null) return false;
        } else if (!remark.equals(other.remark)) {
            return false;
        }
        if (createDate == null) {
            if (other.createDate != null) return false;
        } else if (!createDate.equals(other.createDate)) {
            return false;
        }
        if (modifyDate == null) {
            if (other.modifyDate != null) return false;
        } else if (!modifyDate.equals(other.modifyDate)) {
            return false;
        }
        return true;
    }



}
